//5,4,2,3,2,4,9
//10
// 第一行是代表团人数, 第二行是 车的容量, 暴力会超时, 所以使用动规
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n; // 车的载客量
let initArr = [];
rl.on("line", (line)=>{
    if(initArr.length === 0) {
        initArr = line.trim().split(",").map(Number)
    } else if(n === undefined) {
        n = Number(line.trim())
        console.log(getResult(n, initArr))

        // clear
        initArr.length = 0
        n = undefined
    }

})

function getResult(n, initArr) {
    // init
    let m = initArr.length
    let dp = new Array(m + 1).fill(null).map(_ => new Array(n + 1).fill(0))
    dp[0][0] = 1
    for (let i = 1; i <= m ; i++) {
        for (let j = 0; j <= n ; j++) {
            let weight = initArr[i - 1]
            if(weight <= j) {
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - weight ]
            } else {
                dp[i][j] = dp[i - 1][j]
            }
        }
    }
    return dp[m][n]
}